<template>
	<view>
		<!-- 自定义导航栏 -->
		<z-nav-bar v-if="!isWxBrowser" transparentFixedFontColor="#000" :scrollTop="scrollTop" type="transparentFixed" backState="2000" title="广场"></z-nav-bar>
		<view class="h-bg" :style="'background-image: url('+headBgImg+');'">
			<view class="box-item flex column">
				<u-search placeholder="输入活动关键词" v-model="keyword" :show-action="false" bgColor="#FFFFFF" placeholderColor="#BDC5D4" @search="search()"></u-search>
			</view>
		</view>
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<view class="main">
			<!-- 切换栏 -->
			<view class="qiehuan flex align-item">
				<view class="qiehuan-item flex align-item column">
					<view class="qiehuan-item-tit-com" :class="type == 0 ? 'qiehuan-item-tit-on' : 'qiehuan-item-tit'" @click="change(0)">
						全部
					</view>
					<view class="qiehuan-item-icon" v-if="type == 0"></view>
				</view>
				<view class="qiehuan-item flex align-item column">
					<view class="qiehuan-item-tit-com" :class="type == 1 ? 'qiehuan-item-tit-on' : 'qiehuan-item-tit'" @click="change(1)">
						进行中
					</view>
					<view class="qiehuan-item-icon" v-if="type == 1"></view>
				</view>
				<view class="qiehuan-item flex align-item column">
					<view class="qiehuan-item-tit-com" :class="type == 2 ? 'qiehuan-item-tit-on' : 'qiehuan-item-tit'" @click="change(2)">
						已结束
					</view>
					<view class="qiehuan-item-icon" v-if="type == 2"></view>
				</view>
			</view>
			
			<view class="activity-list" v-if="total > 0">
				<view class="list-item"
				 @click="goDetail(item.activity_id)" 
				 v-for="(item,index) in activityData"
				:key="index">
					<image :src="item.fengmiantu" mode=""></image>
					<view class="" style="position: absolute;top: 0;padding: 24rpx;width: 100%;height: 100%;;background-color: rgba(0, 0, 0, .4);">
						<view class="item-infos flex align-item j-between">
							<view class="item-infos-left">
								{{item.title}}
							</view>
							<!-- <view class="item-infos-right">
								报名开始时间：{{ item.sign_up_start_time }}
							</view> -->
						</view>
						<view class="item-infos flex align-item">
							<view class="item-infos-right">
								报名开始时间：{{ item.sign_up_start_time }}
							</view>
						</view>
						<view class="item-sub-tit">
							{{ item.subtitle }}
						</view>
						<view class="item-address flex align-item j-between">
							<view class="item-address-left">
								地址：{{ item.address }}
							</view>
							<view class="item-address-right qubaoming" v-if="item.type == '进行中'">
								进行中
							</view>
							<!-- <view class="item-address-right weikaishi" v-if="item.type == '未开始'">
								未开始
							</view> -->
							<view class="item-address-right weikaishi" v-if="item.type == '已结束'">
								已结束
							</view>
							<!-- <view class="item-address-right weikaishi" v-if="item.type == '已报名'">
								已报名
							</view> -->
						</view>
					</view>
					<view class="mask" v-if="item.type == '已结束'"></view>
				</view>
			</view>
			
			<view class="" style="margin-top: 200rpx;" v-else>
				<u-empty
				        mode="data"
				        icon="http://cdn.uviewui.com/uview/empty/data.png"
						text=" "
				>
				</u-empty>
			</view>
			
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<tab-bar :current="1"></tab-bar>
		<!-- #endif -->
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			imgUrl: this.$http.baseUrl, // 服务器域名
			headBgImg: this.$http.baseUrl + 'static/web/img/apply-bg.png', // 顶部背景图片
			type: 0, // 切换栏
			uid: '', // 用户id
			activityData: [], // 用户数据
			keyword: '', // 顶部搜索框
			limit: 10, // 每页的请求条件
			page: 1, // 页码
			total: 0, // 数据总数量
			scrollTop: 0, // 顶部导航栏类型
		};
	},
	computed: {
		...mapState(['userInfo']),
	},
	//第一次加载
	onLoad(e) {
		
	},
	onReady() {
		
	},
	// 监听滑动事件
	onPageScroll(e) {
		this.scrollTop = e.scrollTop
	},
	// 触底触发
	onReachBottom() {
		if(this.activityData.length < this.total){
			this.page++
			this.getActivityData()
		}
	},
	//方法
	methods: {
		// 点击搜索
		search(){
			this.page = 1
			this.activityData = []
			this.getActivityData()
		},
		// 切换tab栏
		change(i){
			this.type = i
			this.page = 1
			this.activityData = []
			this.getActivityData()
			
		},
		// 前往详情页
		goDetail(id){
			uni.navigateTo({
				url: '/pages/square_detail/square_detail?activity_id=' + id
			})
		},
		// 获取活动
		getActivityData(){
			var that = this
			that.$http.get('api/ZhActivity/index',{
				'type': that.type,
				'title': that.keyword,
				'page': that.page,
				'limit': that.limit
			}).then(res => {
				if(res){
					that.activityData = [...that.activityData,...res.data]
					that.total = res.total
				}
			});
		},
		
	},
	//页面显示
	onShow() {
		
		var userInfo = this.$store.state.userInfo;
		this.uid = userInfo.uid
		this.activityData = []
		this.total = 0
		this.page = 1
		this.getActivityData()
	},
	//页面隐藏
	onHide() {},
	//页面卸载
	onUnload() {
		
	},
	//用户点击分享
	onShareAppMessage(e) {
		return this.wxShare();
	}
};
</script>
<style>
page {
	background-color: #FFFFFF;
}
</style>
<style lang="scss" scoped>

.flex {
	display: flex;
}
.align-item {
	align-items: center;
}
.j-between {
	justify-content: space-between;
}
.column {
	flex-direction: column;
}
.h-bg {
	width: 100%;
	padding: 196rpx 0 64rpx;
	// #ifdef H5
	padding: 120rpx 0 64rpx;
	// #endif
	.box-item {
		margin: 0 30rpx 30rpx;
	}
}
.uni-searchbar__box.data-v-1854464d {
	border: none !important;
}
.main {
	padding: 24rpx 30rpx;
	// #ifdef MP-WEIXIN
	padding: 24rpx 30rpx 280rpx;
	// #endif
	background-color: #fff;
	border-radius: 40rpx 40rpx 0rpx 0rpx;
	margin-top: -60rpx;
	.qiehuan {
		.qiehuan-item {
			margin-right: 64rpx;
			.qiehuan-item-tit-com {
				display: flex;
				align-items: flex-end;
				font-family: PingFangSC-Light, PingFang SC;
				height: 56rpx;
				margin-bottom: 20rpx;
				vertical-align: baseline;
			}
			.qiehuan-item-tit {
				font-size: 28rpx;
				font-weight: 300;
				color: #6A6A7E;
			}
			.qiehuan-item-tit-on {
				font-size: 40rpx;
				font-weight: 600;
				color: #000013;
			}
			.qiehuan-item-icon {
				width: 20rpx;
				height: 10rpx;
				background: #7F5AFF;
				border-radius: 10rpx 10rpx 0 0;
			}
		}
	}
	.activity-list {
		.list-item {
			position: relative;
			width: 690rpx;
			height: 280rpx;
			border-radius: 24rpx;
			margin-top: 30rpx;
			overflow: hidden;
			image {
				width: 100%;
				height: 100%;
			}
			.item-infos {
				.item-infos-left {
					font-size: 30rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #FFFFFF;
				}
				.item-infos-right {
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
				}
			}
			.item-sub-tit {
				font-size: 20rpx;
				font-family: PingFangSC-Light, PingFang SC;
				font-weight: 300;
				color: #FFFFFF;
				margin: 10rpx 0 66rpx;
			}
			.item-address {
				.item-address-left {
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
				}
				.item-address-right {
					width: 120rpx;
					height: 48rpx;
					border-radius: 28rpx;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					line-height: 48rpx;
					text-align: center;
				}
				.qubaoming {
					background: #FFFFFF;
					color: #000013;
				}
				.weikaishi {
					background: #BEC6D3;
					color: #FFFFFF;
				}
			}
			.mask {
				position: absolute;
				top: 0;
				width: 100%;
				height: 100%;
				background-color: rgba($color: #000000, $alpha: 0.4); 
			}
		}
	}
}
</style>
